﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
namespace CMN.Entity
{
    /// <summary>
    /// 分页存储过程查询参数类
    /// </summary>
    public class QueryParam
    {
        public Object Clone()  //对外提供一个创建自身的浅表副本的能力
        {
            return this.MemberwiseClone();
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        public QueryParam()
            : this(1, int.MaxValue)
        { }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_mPageIndex">当前页码</param>
        /// <param name="_mPageSize">每页记录数</param>
        public QueryParam (int _mPageIndex, int _mPageSize)
        {
            _PageIndex = _mPageIndex;
            _PageSize = _mPageSize;
        }

      

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_mWhere">查询条件 需带Where</param>
        /// <param name="_mPageIndex">当前页码</param>
        /// <param name="_mPageSize">每页记录数</param>
        public QueryParam(string _mWhere,  int _mPageIndex, int _mPageSize)
        {
            _Where = _mWhere;
         
            _PageIndex = _mPageIndex;
            _PageSize = _mPageSize;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_mWhere">查询条件 需带Where</param>
        /// <param name="_mOrderfld">排序字段</param>
        /// <param name="_mOrderType">排序类型 1:降序 其它为升序</param>
        /// <param name="_mPageIndex">当前页码</param>
        /// <param name="_mPageSize">每页记录数</param>
        public QueryParam(string _mWhere,string _mOrderfld,
            int _mPageIndex, int _mPageSize)
        {
            _Where = _mWhere;
            _Orderfld = _mOrderfld;
          
            _PageIndex = _mPageIndex;
            _PageSize = _mPageSize;
        }



        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_mTableName">表名</param>
        /// <param name="_mReturnFields">返回字段</param>
        /// <param name="_mWhere">查询条件 需带Where</param>
        /// <param name="_mOrderfld">排序字段</param>
        /// <param name="_mOrderType">排序类型 1:降序 其它为升序</param>
        /// <param name="_mPageIndex">当前页码</param>
        /// <param name="_mPageSize">每页记录数</param>
        public QueryParam(string _mTableName, string _mReturnFields,
            string _mWhere, string _mOrderfld,
             int _mPageIndex, int _mPageSize)
        {
            _TableName = _mTableName;
            _ReturnFields = _mReturnFields;
            _Where = _mWhere;
            _Orderfld = _mOrderfld;
            _PageIndex = _mPageIndex;
            _PageSize = _mPageSize;
        }



        #region "Private Variables"
        private string _TableName = string.Empty;
        private string _ReturnFields = string.Empty;
        private string _Where=string.Empty;
        private string _Orderfld = string.Empty;
        private int _PageIndex = 1;
        private int _PageSize = 0;
        private string _notInRowName = string.Empty;
        private int pageCount = 0;
        private bool _IsTimeSearch = false;
        private DbParameter[] _cmdParms = null;
        private bool isReturnCount = true;
        #endregion

        #region "Public Variables"

        /// <summary>
        /// MsSql中not in（。。）查询字段，可以为空
        /// </summary>
        public string NotInRowName
        {
            get { return _notInRowName; }
            set { _notInRowName = value; }
        }
        /// <summary>
        /// 是否返回总数
        /// </summary>
        public bool IsReturnCount
        {
            get { return isReturnCount; }
            set { isReturnCount = true; }
        }
        /// <summary>
        /// 参数化查询
        /// </summary>
        public DbParameter[] CmdParms { get { return _cmdParms; } set { _cmdParms = value; } }

        /// <summary>
        /// 表名
        /// </summary>
        public string TableName
        {
            get
            {
                return _TableName;
            }
            set
            {
                _TableName = value;
            }

        }



        /// <summary>
        /// 返回字段
        /// </summary>
        public string ReturnFields
        {
            get
            {
                return _ReturnFields;
            }
            set
            {
                _ReturnFields = value;
            }
        }




        /// <summary>
        /// 查询条件 需带Where
        /// </summary>
        public string Where
        {
            get
            {
                return _Where;
            }
            set
            {
                _Where = value;
            }
        }





        /// <summary>
        /// 排序字段
        /// </summary>
        public string Orderfld
        {
            get
            {
                return _Orderfld;
            }
            set
            {
                _Orderfld = value;
            }
        }


        /// <summary>
        /// 当前页码
        /// </summary>
        public int PageIndex
        {
            get
            {
                return _PageIndex;
            }
            set
            {
                _PageIndex = value;
            }

        }


        /// <summary>
        /// 每页记录数
        /// </summary>
        public int PageSize
        {
            get
            {
                return _PageSize;
            }
            set
            {
                _PageSize = value;
            }
        }
        /// <summary>
        /// 总记录数
        /// </summary>
        public int Count { get; set; }
        /// <summary>
        /// 栏目ID
        /// </summary>
        public string ChannelId = "";
        /// <summary>
        /// 总页数
        /// </summary>
        public int PageCount {
            get
            {
                if(Count<=0){
                    return 0;
                }
                
                if ((Count % PageSize) == 0)
                {
                    this.pageCount = Count / PageSize;
                }
                else
                {
                    this.pageCount = Count / PageSize + 1;
                }
                return this.pageCount;
            }
        }

        /// <summary>
        /// 保存路径
        /// </summary>
        public string SavePath
        {
            get;
            set;
        }
        /// <summary>
        /// 查询类型
        /// </summary>
        public string ModuleType
        {
            get;
            set;
        }
        /// <summary>
        /// 缓存时间
        /// </summary>
        public int TimeTemp
        {
            get;
            set;
        }
        /// <summary>
        /// 查询是否包括时间
        /// </summary>
        public bool IsTimeSearch
        {
            get { return _IsTimeSearch; }
            set { _IsTimeSearch = value; }
        }
        #endregion
    }
}
